﻿// get URL parameters
$.urlParam = function(name){
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if (!results) { return 0; }
	return results[1] || 0;
}

function setCookie(name, value, exdays, path, domain, secure){
	var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
	var expires = d.toUTCString();
    document.cookie= name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ("; path=/") + 
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function accordion() {
	$(".accordion").each(function(){
		var $accordion = $(this);
		var $panels = $(".box > section",this);
		$(".box header h3").click(function(){
			var $switch = $(this);
			$panels.filter(":visible, :animated").stop(true,true).slideUp(200, function() { $accordion.find(".open").removeClass("open"); });
			$switch.parent().next().filter(":hidden").stop(true,true).slideDown(200, function() { $switch.closest(".box").addClass("open"); });
			return false;
		});
	});
}

// DOM Ready
$(function(){

	// placeholder texts
	$('[placeholder]').focus(function () {
		var input = $(this);
		if (input.val() === input.attr('placeholder')) input.val('');
	}).blur(function () {
		var input = $(this);
		if (input.val() === '' || input.val() === input.attr('placeholder')) input.val(input.attr('placeholder'));
	}).blur().parents('form').submit(function () {
		$(this).find('[placeholder]').each(function () {
			var input = $(this);
			if (input.val() === input.attr('placeholder')) input.val('');
		});
	});

	// slider
	$('.slider').each(function(){ $(this).slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		container: 'slides',
		play: 5000,
		pause: 2500,
		hoverPause: true
		});
	});
	
	// iOS like scrollbar
	$(".sidemenu nav, .sidemenu .info.long").each(function() { 
		$(this).niceScroll({
			cursorcolor:"#e2a559",
			cursorborder: "0",
			zindex: 100,
			//	autohidemode: false,
			railoffset: {top:-2,left:0},
			background: "#f2f2f2"
		});
	});
	
	// mainmenu
	/*
	var positioningInProgress = false;
	$("#mainmenu").mouseover(function() {
		if(!positioningInProgress) {
			positioningInProgress = true;
			var pos = $('#mainmenu').offset().top-40;
			$('html,body').animate({scrollTop: pos}, 1000, function() { positioningInProgress = false; });
			
		    var e = jQuery.Event("keyup"); // or keypress/keydown
		    e.keyCode = 27; // for Esc
		    $(document).trigger(e); // trigger it on document
		}
		firstPositioning = false;
	 });
	*/
	// accordion
	accordion();
	
	$(".sideinfo .cols").each(function(){ $(this).masonry({ gutterWidth: 20 }) });
	
	// long contents
	$(".content > .fl > .summary").each(function(){
		var $summary = $(this);
		var $details = $summary.next(".details");
		var $pager = $details.next(".pager");
		var $more = $pager.children(".more");
		$more.click(function(){
			$pager.slideUp(100,function() {
				$details.slideDown(200, function() {
					$pager.remove();
				});
			});
			return false;
		});
	});


	// Tabs
	$(".tabs a").click(function(index,element){
		$(".tabcontents .content:visible").slideUp(200);
		$(this).parent().addClass("active").siblings().removeClass("active");
		$($(this).attr("href")).slideDown(200);
		return false;
	}).eq(0).click();

	// Breadcrumbs
	if($('#breadcrumbs')) {
		var breadWidth = $('#breadcrumbs').width();
		$('#breadcrumbs').css({ width: "800px" });
		if(breadWidth > 800)  {
			$('#breadcrumbs').css({ width: "850px", cursor: "w-resize" });
			$("#breadcrumbs").mousewheel(function(event, delta) {
				this.scrollLeft -= (delta * 30);
				event.preventDefault();
			});
		}
	}
	
	/*
	if($('.sidemenu').length > 0) {
		$(".sidemenu a[title]").tooltip();
	}
	*/
	
   /*$("body").mousewheel(function(event, delta) {

	  this.scrollLeft -= (delta * 30);
	
	  event.preventDefault();

   });*/
});

/*
// body onload
$(window).load(function(){
	// Google map - single address
	$(".gmap.spot").each(function(){
		var $this = $(this);
		var address = $this.data('address');
		var title = $this.data('title');
		var lat = $this.data('lat') || 47.162490;
		var lng = $this.data('lng') || 19.33304;
		
		var mapcenter = new google.maps.LatLng(lat,lng);
		var bounds = new google.maps.LatLngBounds();
		var mapOptions = {
		  zoom: 11,
		  center: mapcenter,
		  mapTypeId: google.maps.MapTypeId.ROADMAP,
		  language: "hu"
		};
		var map = new google.maps.Map(this, mapOptions);
		var infowindow = new google.maps.InfoWindow();
		
		var image = 'img/markers/marker.png';
		var latlng = new google.maps.LatLng(lat,lng);
		var markercontent = "<div><strong>"+title+"</strong><br>"+address+"</div>";
		var marker = new google.maps.Marker({
			position: latlng, 
			map: map,
			icon: image,
			title: title
		});

		//init info window
		google.maps.event.addListener(marker, 'click', function() {
			infowindow.setContent(markercontent);
			infowindow.open(map, marker);  
		});

	});	
	
	// Google map - multi address
	$(".gmap.spots").each(function(){

		var source = $(this).data('xml');

		var mapcenter = new google.maps.LatLng(47.162490,19.33304);
		var bounds = new google.maps.LatLngBounds();
		var mapOptions = {
		  zoom: 1,
		  center: mapcenter,
		  mapTypeId: google.maps.MapTypeId.ROADMAP,
		  language: "en"
		};
		var map = new google.maps.Map(this, mapOptions);
		var infowindow = new google.maps.InfoWindow();
		
		if (source !== "") {
			$.ajax({
				url: source,
				success: function(data) {
					
					$(data).find("address").each(function(index,element){
						var $this = $(this);
						var image = 'img/markers/marker'+(index+1)+'.png';
						var latlng = new google.maps.LatLng($this.attr("lat"),$this.attr("lng"));
						var title = $this.attr("title");
						var markercontent = $this.find("description").text();
						var shadow = new google.maps.MarkerImage("img/markers/shadow.png",
							   new google.maps.Size(51.0, 37.0),
							   new google.maps.Point(0, 0),
							   new google.maps.Point(17.0, 37.0)
						);
						var marker = new google.maps.Marker({
							position: latlng, 
							map: map,
							icon: image,
							title: title,
							shadow: shadow
						});
			
						//init info window
						google.maps.event.addListener(marker, 'click', function() {
							infowindow.setContent(markercontent);
							infowindow.open(map, marker);  
						});
			
						// extend bounds with the marker position
						bounds.extend(latlng);
					});
					
					map.fitBounds(bounds);
				}		
			});
		}

	});	
});
*/